﻿using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Scripting;
using Microsoft.Scripting.Ast;
using Microsoft.Linq.Expressions;

namespace DlrBasic.Parser.Ast
{
    class Goto : Statement
    {
        LineNumberTarget target;

        public Goto(SourceSpan span, LineNumberTarget target)
            : base(span)
        {
            this.target = target;
        }

        protected internal override Expression Generate(DlrBasicGenerator generator, StateMemberGenerator stateParameter, LambdaBuilder builder)
        {
            int state = generator.GetLineStatementNumber(target.LineNumber);

            return Utils.Assign(stateParameter.GetCurrentStatementVariable(),
                Utils.Constant(state), target.SourceSpan);
        }
    }
}
